<template>
	<view class="group-detail">
		<rich-text class="richText" :nodes="info.text" @click="showImg($event)" :data-nodes="info.text"></rich-text>
	</view>
</template>

<script>
	import htmlParser from '@/common/js/html-parser';
	export default {
		components: {},
		data() {
			return {
				info: [],
				seed: {},
				id: '',
				site_id: ''
			}
		},
		onShow() {
			this.getSiteMessageRecordsInfo()
		},
		onLoad(param) {
			this.id = param.id
			this.site_id = param.site_id
		},
		methods: {
			getSiteMessageRecordsInfo() {
				this.$api.sendRequest({
					url: '/sitemessage/api/sitemessage/getSiteMessageRecordsInfo',
					data: {
						id: this.id
					},
					success: res => {
						if (res.code == 0) {
							this.info = res.data
							if(this.info.text){
								this.info.text = htmlParser(this.info.text)
							}
							this.getSeed(res.data.id, res.data.site_id)
						}
					}
				});
			},
			// 消息主表点击已接收
			getSeed(id, site_id) {
				this.$api.sendRequest({
					url: '/sitemessage/api/sitemessage/seed',
					data: {
						id: id,
						site_id: site_id
					},
					success: res => {
						if (res.code == 0) {
							this.seed = res.data
						}
					}
				});
			},
			showImg(e) {
				//拿到图片的路径里面的内容放在我们数组中
				let contentimg = e.target.dataset.nodes;
				let arrImg = [];
				for (var i = 0; i < contentimg.length; i++) {
					var img = contentimg[i].children;
					if (Array.isArray(img)) {
						for (var j = 0; j < img.length; j++) {
							if (img[j].attrs && img[j].name == "img") {
								if (img[j].attrs.src) {
									arrImg.push(img[j].attrs.src)
								}
							}
						}
					}
				}
				//最后一步就是把我们的所有图片放在预览的api中就可以了
				uni.previewImage({
					current: arrImg,
					urls: arrImg,
				})
			},
		},
	}
</script>

<style lang="scss">
	.group-detail {
		padding: 30rpx;
	}

	.richText /deep/ image {
		max-width: 100% !important;
	}

	rich-text image {
		max-width: 100%;
	}
</style>